<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/reset.css">
    <style>
        img{
            width: 400px;
        }
    </style>
</head>
<body>
    <button class="change">切换</button>
    <div>
        <a href="https://www.baidu.com" target="_self">
            <img src="../images/bg.jpg" alt="">
        </a>
    </div>
</body>
<script>

    // href  获取和设置元素href属性 (a link)
    // target 获取和设置元素target属性
    
    // src    获取和设置元素src属性  (img video script)
    // alt    获取和设置元素alt属性

    var change = document.getElementsByClassName("change")[0];
    var a = document.getElementsByTagName("a")[0];
    var img = document.getElementsByTagName("img")[0];

    var isSwitch = false; // 全局变量 记录是否切换

    change.onclick = function(){
        console.log(a.href);
        console.log(img.src);   

        if(!isSwitch){
            a.href = "https://www.jd.com";
            img.src = "../images/bg_1.jpeg";
            isSwitch = true;
        }else{
            a.href = "https://www.baidu.com";
            img.src = "../images/bg.jpg";
            isSwitch = false;
        }
    }



</script>
</html>